package com.rrqs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.rrqs.utils.DateUtils;
import com.zadtek.xmqishi.R;

import java.util.Date;

/**
 * 我的统计
 * @author kuyukeji
 *
 */
public class MytjDayFragment extends FragmentActivity{

	private ImageView backid,iv_rili;
	private TextView topview, rightname; // 标题,右边的标题

	private RadioGroup radioGroup;
	private FragmentTransaction fragmentTrans;

	private MytjChildFragment fragment;	//我的统计

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_mytj);
		
		backid = (ImageView) findViewById(R.id.backid);
		backid.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		topview = (TextView) findViewById(R.id.topview);
		topview.setText("我的统计");
		rightname = (TextView) findViewById(R.id.rightname);
		rightname.setVisibility(View.GONE);
		iv_rili = (ImageView) findViewById(R.id.iv_rili);
		iv_rili.setVisibility(View.VISIBLE);
		iv_rili.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(v.getContext(), DatePickerActivity.class), 1000);
			}
		});

		radioGroup = (RadioGroup) findViewById(R.id.tab_radio);
		radioGroup.setVisibility(View.GONE);
		fragmentTrans = getSupportFragmentManager().beginTransaction();
		if (fragment == null) {	//默认显示第一个
			fragment = new MytjChildFragment();
			fragmentTrans.add(R.id.layout_content, fragment).commit();
        }

		String time1 = getIntent().getStringExtra("date");
		fragment.setTime(time1);
		getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();

		topview.setText("我的统计"+"("+time1+")");
	}


	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) {
			assert data != null;
			if (requestCode == 1000) {
				Date date = new Date(data.getLongExtra("date", 0));
				fragment.setTime(DateUtils.convertDateToStr(date, "yyyyMMdd"));

				topview.setText("我的统计"+"("+DateUtils.convertDateToStr(date, "yyyyMMdd"+")"));

				fragment.refresh();
//				getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

}
